<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
             label-width="68px">
      <el-form-item label="企业名称" prop="disposalLandName">
        <el-input
          v-model="queryParams.disposalLandName"
          placeholder="请输入企业名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="出厂时间">
        <el-date-picker
          v-model="daterangeCreateData"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索
        </el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['report:outcomingreport:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="outcomingreportList"
              @selection-change="handleSelectionChange">
      <el-table-column prop="id" label="序号" type="index">
        <template slot-scope="scope">
          <span v-if="scope.$index != outcomingreportList.length-1">{{(queryParams.current - 1) * queryParams.size + scope.$index + 1}}</span>
        </template>
      </el-table-column>
      <el-table-column label="企业名称" align="center" prop="disposalLandName"/>
      <el-table-column label="出厂时间" align="center" prop="createData" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createData, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="再生产品出厂量" align="center" prop="netWeight"/>
      <el-table-column label="再生产品出厂金额" align="center" prop="amount"/>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.current"
      :limit.sync="queryParams.size"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {listOutcomingreport} from "@/api/report/outcomingreport";

export default {
  name: "Outcomingreport",
  dicts: ['weighing_type', 'garbage_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 垃圾出场量统计表格数据
      outcomingreportList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 过磅类型( 10:进厂;20:出厂 )时间范围
      daterangeCreateData: [],
      // 查询参数
      queryParams: {
        current: 1,
        size: 10,
        disposalLandName: null,
        createData: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询垃圾出场量统计列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeCreateData && '' != this.daterangeCreateData) {
        this.queryParams.params["beginCreateData"] = this.daterangeCreateData[0];
        this.queryParams.params["endCreateData"] = this.daterangeCreateData[1];
      }
      listOutcomingreport(this.queryParams).then(response => {
        this.outcomingreportList = response.records;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        disposalLandId: null,
        serialNumber: null,
        carNumber: null,
        shipper: null,
        receivingUnit: null,
        goodsName: null,
        specification: null,
        grossWeightman: null,
        tareWeigher: null,
        grossHeavyweight: null,
        tareHeavy: null,
        createData: null,
        grossWeightTime: null,
        tareTime: null,
        weighingTime: null,
        secondWeighingTime: null,
        garbageWeight: null,
        grossWeight: null,
        tare: null,
        deduction: null,
        netWeight: null,
        unitPrice: null,
        amount: null,
        factor: null,
        squareAmount: null,
        weighingFee: null,
        oneWeighing: null,
        secondWeighing: null,
        grossImg: null,
        tareImg: null,
        garbageType: null,
        weighingType: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.current = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeCreateData = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('report/outcomingreport/export', {
        ...this.queryParams
      }, `outcomingreport_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
